import RichTextEditor from '@/component/common/richText'

export interface EssayProps {
  data?: string
  state: 'QUESTYPE' | 'WRITE' | 'READ' | 'PREVIEW' | 'TODO'
  onChange?: (data: any) => void
}
export default function Essay(props: EssayProps) {
  let { data = '', state = 'QUESTYPE', onChange = () => {} } = props
  if (state === 'QUESTYPE') {
    data = ''
  }

  if (state === 'TODO') {
    return (
      <div>
        <RichTextEditor
          content={data}
          state="WRITE"
          onChange={(data) => {
            const value = data.getJSON()
            onChange(value)
          }}></RichTextEditor>
      </div>
    )
  }

  return (
    <div style={{ width: '50%' }}>
      <RichTextEditor
        state={state}
        onChange={(data) => {
          const value = data.getJSON()
          onChange(value)
        }}></RichTextEditor>
    </div>
  )
}
